#include "LogSubject.h"
#include "monitor_public_def.h"

CLogSubject::CLogSubject()
{
}


CLogSubject::~CLogSubject()
{
}


void CLogSubject::WriteLog(unsigned int logCmd, unsigned int loglvl, const char * format, ...)
{
	LOG_DATA data;
	data.level = loglvl;

	time_t now;
	struct tm *tm_now;
	time(&now);
	tm_now = localtime(&now);

	char szShow[32];

	sprintf(szShow, "%04d-%02d-%02d"
		, tm_now->tm_year + 1900, tm_now->tm_mon + 1, tm_now->tm_mday);
	data.date = szShow;

	sprintf(szShow, "%02d:%02d:%02d"
		, tm_now->tm_hour, tm_now->tm_min, tm_now->tm_sec);
	data.time = szShow;

	char strMsg[1024];
	va_list ap;
	va_start(ap, format);
	_vsnprintf(strMsg, 1024, format, ap);
	va_end(ap);
	data.text = strMsg;

	StringReplace(data.text, "\r\n", "");
	StringReplace(data.text, "\n", "");
	Update(logCmd, (UINT_PTR)&data, (LONG_PTR)0);
}